<script type="text/javascript">

  import store from './../store'
  const BASE_OSS_URL = 'https://yqlife-dev.oss-cn-hangzhou.aliyuncs.com/';//全局配置的图片引用地址

  // 定义一些公共的属性和方法
  const TYPE_NORMAL = 0;//无操作
  const TYPE_LINK_SUBJECT = 10;//专题链接
  const TYPE_LINK_ACTIVE = 15;//链接产品
  const TYPE_LINK_CATEGORY = 20;//链接分类
  const TYPE_OTHER_LINK = 50;//外部链接
  //站点状态-start
  const STATUS_NORMAL = 0;//正常状态
  const STATUS_EXPIRATION = 1;//过期状态
  //站点状态-end
  
  //发货方式-start
  const TRANSPORT_TYPE_QRCODE = 0;//到店二维码核销
  const TRANSPORT_TYPE_EXPRESS= 1;//快递发货
  const TRANSPORT_TYPES = [
    {name: '二维码核销', value: TRANSPORT_TYPE_QRCODE},
    {name: '快递发货', value: TRANSPORT_TYPE_EXPRESS}
  ];
  //发货方式-end
  
  //用户类型-start
  const USER_TYPE_NORMAL = 0;//普通用户
  const USER_TYPE_VIP = 1;//VIP用户
  //用户类型-end

  //活动类型-start
  const ACTIVE_TYPE_QG = 0;//抢购
  const ACTIVE_TYPE_QG_XS = 1;//限时抢购
  const ACTIVE_TYPE_KJ = 5;//砍价
  const ACTIVE_TYPE_VIP = 10;//vip
  const ACTIVE_TYPES = [
    {name: '抢购', value: ACTIVE_TYPE_QG},
    {name: '限时抢购', value: ACTIVE_TYPE_QG_XS},
    {name: '砍价', value: ACTIVE_TYPE_KJ}
  ];
  //活动类型-end
  //支付类型-start
  const PAY_TYPE_ONLINE = 0;//线上支付
  const PAY_TYPE_OFFLINE = 1;//到店支付
  const PAY_TYPES = [
    {name: '线上支付', value: PAY_TYPE_ONLINE},
    {name: '到店支付', value: PAY_TYPE_OFFLINE},
  ];
  //支付类型-end
  //活动状态-start
  const ACTIVE_STATUS_SAVED = 0;//已保存
  const ACTIVE_STATUS_WAIT = 5;//未开始
  const ACTIVE_STATUS_NORMAL = 10;//进行中
  const ACTIVE_STATUS_STOP = 15;//暂停
  const ACTIVE_STATUS_END = 20;//结束
  const ACTIVE_SOLD_OUT = 30;//卖完了
  const ACTIVE_STATUS = [
    {name: '已保存', value: ACTIVE_STATUS_SAVED},
    {name: '未开始', value: ACTIVE_STATUS_WAIT},
    {name: '进行中', value: ACTIVE_STATUS_NORMAL},
    {name: '暂停', value: ACTIVE_STATUS_STOP},
    {name: '结束', value: ACTIVE_STATUS_END},
    {name: '售完', value: ACTIVE_SOLD_OUT},
  ];
  //活动类型-end

  //活动显示状态-start
  const ACTIVE_SHOW_NO = 0;//
  const ACTIVE_SHOW_YES = 1;//
  const ACTIVE_SHOWS = [{name: '不显示', value: ACTIVE_SHOW_NO}, {name: '显示', value: ACTIVE_SHOW_YES}];//
  //活动类型-end
  //付款状态
  const PAY_STATUS_UN_PAY_ONLINE = 0;//线上未付款
  const PAY_STATUS_PAID_FAILED_ONLINE = 4;//线上付款失败
  const PAY_STATUS_PAID_ONLINE = 5;//线上已付款
  const PAY_STATUS_UN_PAY_OFFLINE = 10;//线下未付款
  const PAY_STATUS_PAID_OFFLINE = 15;//线下已付款
  const PAY_STATUS_WAIT_REFUND = 19;//退款中
  const PAY_STATUS_REFUNDED = 20;//已退款

  //订单状态
  const ORDER_STATUS_NORMAL = 0;//订单的正常状态，未付款前或已付款后都是这个状态，已付款后就是待使用
  const ORDER_STATUS_USED = 5;//已使用AND待评价
  const ORDER_STATUS_CLOSE = 10;//关闭
  const ORDER_STATUS_EXPIRE = 15;//已过期

  //砍价订单状态
  const KJ_ORDER_STATUS_NORMAL = 0;
  const KJ_ORDER_STATUS_CLOASE = 1;
  //砍价订单价格状态
  const KJ_ORDER_IS_LOWEST_NO = 0;
  const KJ_ORDER_IS_LOWEST_YES = 1;

  //订单自动关闭时间
  const ORDER_AUTO_CLOSE_TIME = 60*5;
  //订单类型
  const TYPE_VIP_ORDER=0;
  const TYPE_GOODS_ORDER=1;

  function commonFun() {
    console.log("公共方法")
  }

  /**
   * 获取全路径oss文件地址
   * @param orgUrl 相对地址
   * @param small 是否是小图
   * @param icon 是否是图标
   * @returns {string}
   */
  function getUrl(orgUrl,small=false,icon=false) {
    let url = store.getters.config['baseImgUrl'];
    return url+orgUrl+(small?'!small':'')+(icon?'!icon':'');
  }

  function convertUTCTimeToLocalTime(UTCDateString) {
    if (!UTCDateString) {
      return '-';
    }

    function formatFunc(str) {    //格式化显示
      return str > 9 ? str : '0' + str
    }

    let date2 = new Date(UTCDateString);     //这步是关键
    let year = date2.getFullYear();
    let mon = formatFunc(date2.getMonth() + 1);
    let day = formatFunc(date2.getDate());
    let hour = date2.getHours();
    // let noon = hour >= 12 ? 'PM' : 'AM';
    // hour = hour >= 12 ? hour - 12 : hour;
    // hour = formatFunc(hour);
    let min = formatFunc(date2.getMinutes());

    return year + '-' + mon + '-' + day + ' ' + hour + ':' + min;
  }
  //格式化价格
  function formatPrice(price) {    //格式化显示
    return price/100;
  }

  // 暴露出这些属性和方法
  export default {
    TYPE_VIP_ORDER,
    TYPE_GOODS_ORDER,
    KJ_ORDER_STATUS_NORMAL,
    KJ_ORDER_STATUS_CLOASE,
    KJ_ORDER_IS_LOWEST_NO,
    KJ_ORDER_IS_LOWEST_YES,
    BASE_OSS_URL,
    TYPE_NORMAL,
    TYPE_LINK_SUBJECT,
    TYPE_LINK_ACTIVE,
    TYPE_LINK_CATEGORY,
    TYPE_OTHER_LINK,
    STATUS_NORMAL,
    STATUS_EXPIRATION,
    ACTIVE_TYPE_QG,
    ACTIVE_TYPE_QG_XS,
    ACTIVE_TYPE_KJ,
    ACTIVE_TYPE_VIP,
    ACTIVE_TYPES,
    PAY_TYPE_ONLINE,
    PAY_TYPE_OFFLINE,
    PAY_TYPES,
    ACTIVE_STATUS_SAVED,
    ACTIVE_STATUS_WAIT,
    ACTIVE_STATUS_NORMAL,
    ACTIVE_STATUS_STOP,
    ACTIVE_STATUS_END,
    ACTIVE_SOLD_OUT,
    ACTIVE_STATUS,
    ACTIVE_SHOW_NO,
    ACTIVE_SHOW_YES,
    ACTIVE_SHOWS,
    USER_TYPE_NORMAL,
    USER_TYPE_VIP,
    TRANSPORT_TYPES,
    TRANSPORT_TYPE_QRCODE,
    TRANSPORT_TYPE_EXPRESS,
    PAY_STATUS_UN_PAY_ONLINE,
    PAY_STATUS_PAID_FAILED_ONLINE,
    PAY_STATUS_PAID_ONLINE,
    PAY_STATUS_UN_PAY_OFFLINE,
    PAY_STATUS_PAID_OFFLINE,
    PAY_STATUS_WAIT_REFUND,
    PAY_STATUS_REFUNDED,
    ORDER_STATUS_EXPIRE,
    ORDER_STATUS_NORMAL,
    ORDER_STATUS_USED,
    ORDER_STATUS_CLOSE,
    ORDER_AUTO_CLOSE_TIME,
    commonFun,
    formatPrice,
    convertUTCTimeToLocalTime,
    getUrl
  }
</script>
